
(define-library (aop 11)
  (import (scheme base))
  (export last-pair append! lookup)
  (begin
    (define (last-pair x)
      (if (pair? (cdr x))
          (last-pair (cdr x))
          x))

    (define (append! ls1 ls2)
      (if (pair? ls1)
          (begin
            (set-cdr! (last-pair ls1) ls2)
            ls1)
          ls2))

    (define (lookup obj table success-proc failure-proc)
      (letrec ((lookup (lambda (table)
                         (if (null? table)
                             (failure-proc)
                             (let ((pr (car table)))
                               (if (equal? (car pr) obj)
                                   (success-proc pr)
                                   (lookup (cdr table))))))))
        (lookup table)))))
